<?php
/*
 * Zend Framework Includes
 */
ini_set('include_path', '.:./:../:../../:../../../:/Zend:./Zend:../Zend:../../Zend:../../../Zend:'.$_SERVER[DOCUMENT_ROOT].'/Zend');
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Json.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Db/Adapter/Pdo/Mysql.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Db.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Date.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Mail.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Validate/EmailAddress.php';
require_once $_SERVER[DOCUMENT_ROOT].'/Zend/Session/Namespace.php';

/*
 * Session stuff
 */
ini_set('session.save_path',$_SERVER[DOCUMENT_ROOT].'/data/session');
ini_set('session.gc_maxlifetime',28800);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);

Zend_Session::start();
$session = new Zend_Session_Namespace('CDC');
$session->setExpirationSeconds(28800, 'logged');

/*
 * REQUIRED & INCLUDE FILES
 */
require_once($_SERVER[DOCUMENT_ROOT]."/admin/includes/config.inc.php");
require_once($_SERVER[DOCUMENT_ROOT]."/admin/includes/functions.php");
require_once($_SERVER[DOCUMENT_ROOT]."/admin/includes/functionsAppEmails.php");

/*
 * Other Class File Includes
 */
require_once($_SERVER[DOCUMENT_ROOT].'/admin/includes/classes/GphpChart.class.php');

/*
 * What page are we on?
 */
$selfArray = explode("/", $_SERVER[PHP_SELF]);
$elements = count($selfArray);
$last_element = $elements - 1;
$thisPage = $selfArray[$last_element];

// Are we logging out?
if ($_GET[logout] == 1) {
	$_SESSION = array();
	if (isset($_COOKIE[session_name()])) {
	    setcookie(session_name(), '', time()-42000, '/');
	}	
	session_destroy();
}

// Are we logged in?
if ($_GET['airAuth'] == 1) {
	
} else {
	if ( ($session->logged != 1) && ($thisPage != 'login.php') && ($thisPage != 'ajaxDirector.php') ) {
		header("Location: login.php");
	} elseif ( ($_SESSION['level'] == 0)  && ($thisPage != 'login.php') && ($thisPage != 'ajaxDirector.php') ) {
		header("Location: login.php");
	}
}	

// Set default timezone
date_default_timezone_set('America/Los_Angeles');

// Database Connection
// Do it the old fashioned way until we get the MySQL PDO driver installed.
$dbname = 'childdis';
$dbhost = 'cougar.wou.edu';
$dbuser = 'childdis';
$dbpass = 'no!dis';
$db = mysql_connect($dbhost,$dbuser,$dbpass);
	
// Check for tab designation. Are we trying to reach a specific tab from the 
// main menu?
if (!empty($_GET[tab])) {
	$onLoad = "mainTabs.setActiveTab('pageTab".$_GET[tab]."');";
}

?>